/** @jsxImportSource @emotion/react */
import * as React from "react";
import {
  Text, Table, TableBody, TableRow, CCell, TableHead, Button,
} from "customize-easy-ui-component";
import {DirectLink, } from "../../routing/Link";

const cfgDefault=[['A','表1 不符合安全技术规范要求必须整改的项目'],
    [undefined,'表2 具有一定潜在安全风险建议整改的项目'],
    ['B','表3 与现行安全技术规范或标准要求不一致的项目']
];
/**评估特别的 正式报告： 表1 2 3 不符合项目 'A', undefined, 'B',三个类别级别；
 * */
export const UnqualifiedIspTableEvalSplit= ({printing, rep,  orc, mapNoTag, original,fixed=["4.5%","9%","%"],config=cfgDefault }
    :{printing:boolean, rep:any, orc:any, mapNoTag?:Map<string,string>, original?:boolean,fixed?:any[],config?:any[]}
) => {
  const urlhead=`/report/${rep?.modeltype}/ver/${rep?.modelversion}/${rep?.id}`;
  return  <>
    { config.map(([iClass,label], i:number) => {
      const unqtb='unq'+(iClass??'');
      const  utag='ReCheck'+(iClass??'');
      return  <React.Fragment key={i}>
        {
          orc?.[unqtb]?  <div>
                <Table id={utag}  fixed={fixed}  css={ {marginTop: '1rem',borderCollapse: 'collapse'} }  tight  miniw={800}>
                  <TableBody>
                    <DirectLink  href={urlhead+`/${utag}#${utag}`}>
                      <TableRow>
                        <CCell  colSpan={5}><Text variant="h4">{label}</Text></CCell>
                      </TableRow>
                    </DirectLink>
                  </TableBody>
                </Table>
                <Table  fixed={fixed} css={ {borderCollapse: 'collapse' } }  tight  miniw={800}>
                  <TableHead>
                    <DirectLink  href={urlhead+`/${utag}#${utag}`}>
                      <TableRow>
                        <CCell>序号</CCell>
                        <CCell>类别/编号</CCell>
                        <CCell>检验不合格内容记录</CCell>
                      </TableRow>
                    </DirectLink>
                  </TableHead>
                  <TableBody>
                    {orc?.[unqtb]?.map((bug:any, i:number) => {
                      return (
                          <TableRow key={i}>
                            <DirectLink key={i} href={urlhead+`/${mapNoTag? mapNoTag.get(bug.no): bug.no}`}>
                              <CCell>{i+1}</CCell>
                              <CCell>{bug.p}{bug.no}{iClass??''}</CCell>
                            </DirectLink>
                            <DirectLink key={i+'r'} href={urlhead+`/${utag}?from=${bug.no}`}>
                              <CCell>{bug.b}</CCell>
                            </DirectLink>
                          </TableRow>
                      );
                    }) }
                  </TableBody>
                </Table>
              </div>
              :
              printing?  null :
                  <DirectLink  href={urlhead+`/${utag}#${utag}`}>
                    <Button variant="ghost" intent='primary' block css={{"@media print": {display: 'none'} }}  noBind >
                      {label}
                    </Button>
                  </DirectLink>
        }
      </React.Fragment>;
    }) }
  </>;
};

/**有整改措施的,正式报告版本：
 * */
export const UnqualifiedIspTableEvalSplitZG= ({printing, rep,  orc, mapNoTag, original,fixed=["3.4%","9%","%","8.1%"] }
                                            :{printing:boolean, rep:any, orc:any, mapNoTag?:Map<string,string>, original?:boolean,fixed?:any[],}
) => {
    const urlhead=`/report/${rep?.modeltype}/ver/${rep?.modelversion}/${rep?.id}`;
    return  <>
        { [['A','表1 不符合安全技术规范要求必须整改的项目'],[undefined,'表2 具有一定潜在安全风险建议整改的项目'],
            ['B','表3 与现行安全技术规范或标准要求不一致的项目']].map(([iClass,label], i:number) => {
            const unqtb='unq'+(iClass??'');
            const  utag='ReCheck'+(iClass??'');
            return  <React.Fragment key={i}>
                {
                    orc?.[unqtb]?  <div>
                            <Table id={utag}  fixed={fixed}  css={ {marginTop: '1rem',borderCollapse: 'collapse'} }  tight  miniw={800}>
                                <TableBody>
                                    <DirectLink  href={urlhead+`/${utag}#${utag}`}>
                                        <TableRow>
                                            <CCell  colSpan={5}><Text variant="h4">{label}</Text></CCell>
                                        </TableRow>
                                    </DirectLink>
                                </TableBody>
                            </Table>
                            <Table  fixed={fixed} css={ {borderCollapse: 'collapse' } }  tight  miniw={800}>
                                <TableHead>
                                    <DirectLink  href={urlhead+`/${utag}#${utag}`}>
                                        <TableRow>
                                            <CCell><Text css={{fontSize: '0.7rem'}}>序号</Text></CCell>
                                            <CCell>类别/编号</CCell>
                                            <CCell>检验不合格内容记录</CCell>
                                            <CCell>整改措施</CCell>
                                        </TableRow>
                                    </DirectLink>
                                </TableHead>
                                <TableBody>
                                    {orc?.[unqtb]?.map((bug:any, i:number) => {
                                        return (
                                            <TableRow key={i}>
                                                <DirectLink key={i} href={urlhead+`/${mapNoTag? mapNoTag.get(bug.no): bug.no}`}>
                                                    <CCell>{i+1}</CCell>
                                                    <CCell>{bug.p}{bug.no}{iClass??''}</CCell>
                                                </DirectLink>
                                                <DirectLink key={i+'r'} href={urlhead+`/${utag}?from=${bug.no}`}>
                                                    <CCell>{bug.b}</CCell>
                                                    <CCell>{bug.c}</CCell>
                                                </DirectLink>
                                            </TableRow>
                                        );
                                    }) }
                                </TableBody>
                            </Table>
                        </div>
                        :
                        printing?  null :
                            <DirectLink  href={urlhead+`/${utag}#${utag}`}>
                                <Button variant="ghost" intent='primary' block css={{"@media print": {display: 'none'} }}  noBind >
                                    {label}
                                </Button>
                            </DirectLink>
                }
            </React.Fragment>;
        }) }
    </>;
};
/**有整改措施的,原始记录用的版本：
 * */
export const UnqualifiedIspTableEvalSplitZGO= ({printing, rep,  orc, mapNoTag, original,fixed=["3.4%","9%","%","8.1%","8.1%"] }
                     :{printing:boolean, rep:any, orc:any, mapNoTag?:Map<string,string>, original?:boolean,fixed?:any[],}
) => {
    const urlhead=`/report/${rep?.modeltype}/ver/${rep?.modelversion}/${rep?.id}`;
    return  <>
        { [['A','表1 不符合安全技术规范要求必须整改的项目'],[undefined,'表2 具有一定潜在安全风险建议整改的项目'],
            ['B','表3 与现行安全技术规范或标准要求不一致的项目']].map(([iClass,label], i:number) => {
            const unqtb='unq'+(iClass??'');
            const  utag='ReCheck'+(iClass??'');
            const nameFJd='复检日'+(iClass??'');       //复检日期每个项目类别才有一个 存储;
            return  <React.Fragment key={i}>
                {
                    orc?.[unqtb]?  <div>
                            <Table id={utag}  fixed={fixed}  css={ {marginTop: '1rem',borderCollapse: 'collapse'} }  tight  miniw={800}>
                                <TableBody>
                                    <DirectLink  href={urlhead+`/${utag}#${utag}`}>
                                        <TableRow>
                                            <CCell  colSpan={5}><Text variant="h4">{label}</Text></CCell>
                                        </TableRow>
                                    </DirectLink>
                                </TableBody>
                            </Table>
                            <Table  fixed={fixed} css={ {borderCollapse: 'collapse' } }  tight  miniw={800}>
                                <TableHead>
                                    <DirectLink  href={urlhead+`/${utag}#${utag}`}>
                                        <TableRow>
                                            <CCell><Text css={{fontSize: '0.7rem'}}>序号</Text></CCell>
                                            <CCell>类别/编号</CCell>
                                            <CCell>检验不合格内容记录</CCell>
                                            <CCell>整改措施</CCell>
                                            <CCell>复检结果</CCell>
                                        </TableRow>
                                    </DirectLink>
                                </TableHead>
                                <TableBody>
                                    {orc?.[unqtb]?.map((bug:any, i:number) => {
                                        return (
                                            <TableRow key={i}>
                                                <DirectLink key={i} href={urlhead+`/${mapNoTag? mapNoTag.get(bug.no): bug.no}`}>
                                                    <CCell>{i+1}</CCell>
                                                    <CCell>{bug.p}{bug.no}{iClass??''}</CCell>
                                                </DirectLink>
                                                <DirectLink key={i+'r'} href={urlhead+`/${utag}?from=${bug.no}`}>
                                                    <CCell>{bug.b}</CCell>
                                                    <CCell>{bug.c}</CCell>
                                                    <CCell>{bug.rs}</CCell>
                                                </DirectLink>
                                            </TableRow>
                                        );
                                    }) }
                                    <TableRow><CCell colSpan={2}>复检日期</CCell><CCell colSpan={3}>{orc?.[nameFJd]}</CCell></TableRow>
                                    <TableRow><CCell colSpan={2}>复检人员</CCell><CCell colSpan={3}></CCell></TableRow>
                                </TableBody>
                            </Table>
                        </div>
                        :
                        printing?  null :
                            <DirectLink  href={urlhead+`/${utag}#${utag}`}>
                                <Button variant="ghost" intent='primary' block css={{"@media print": {display: 'none'} }}  noBind >
                                    {label}
                                </Button>
                            </DirectLink>
                }
            </React.Fragment>;
        }) }
    </>;
};
/**原始记录用的版本：
 * */
export const UnqualifiedIspTableEvalSplitO= ({printing, rep,  orc, mapNoTag, original,fixed=["3.4%","9%","%","8.1%"] }
                                               :{printing:boolean, rep:any, orc:any, mapNoTag?:Map<string,string>, original?:boolean,fixed?:any[],}
) => {
    const urlhead=`/report/${rep?.modeltype}/ver/${rep?.modelversion}/${rep?.id}`;
    return  <>
        { [['A','表1 存在一定安全风险必须整改的项目'],[undefined,'表2 具有一定潜在安全风险建议整改的项目'],
            ['B','表3 采用旧的制造与安装技术建议整改的项目']].map(([iClass,label], i:number) => {
            const unqtb='unq'+(iClass??'');
            const  utag='ReCheck'+(iClass??'');
            const nameFJd='复检日'+(iClass??'');       //复检日期每个项目类别才有一个 存储;
            return  <React.Fragment key={i}>
                {
                    orc?.[unqtb]?  <div>
                            <Table id={utag}  fixed={fixed}  css={ {marginTop: '1rem',borderCollapse: 'collapse'} }  tight  miniw={800}>
                                <TableBody>
                                    <DirectLink  href={urlhead+`/${utag}#${utag}`}>
                                        <TableRow>
                                            <CCell  colSpan={5}><Text variant="h4">{label}</Text></CCell>
                                        </TableRow>
                                    </DirectLink>
                                </TableBody>
                            </Table>
                            <Table  fixed={fixed} css={ {borderCollapse: 'collapse' } }  tight  miniw={800}>
                                <TableHead>
                                    <DirectLink  href={urlhead+`/${utag}#${utag}`}>
                                        <TableRow>
                                            <CCell><Text css={{fontSize: '0.7rem'}}>序号</Text></CCell>
                                            <CCell>类别/编号</CCell>
                                            <CCell>检验不合格内容记录</CCell>
                                            <CCell>复检结果</CCell>
                                        </TableRow>
                                    </DirectLink>
                                </TableHead>
                                <TableBody>
                                    {orc?.[unqtb]?.map((bug:any, i:number) => {
                                        return (
                                            <TableRow key={i}>
                                                <DirectLink key={i} href={urlhead+`/${mapNoTag? mapNoTag.get(bug.no): bug.no}`}>
                                                    <CCell>{i+1}</CCell>
                                                    <CCell>{bug.p}{bug.no}{iClass??''}</CCell>
                                                </DirectLink>
                                                <DirectLink key={i+'r'} href={urlhead+`/${utag}?from=${bug.no}`}>
                                                    <CCell>{bug.b}</CCell>
                                                    <CCell>{bug.rs}</CCell>
                                                </DirectLink>
                                            </TableRow>
                                        );
                                    }) }
                                    <TableRow><CCell colSpan={2}>复检日期</CCell><CCell colSpan={2}>{orc?.[nameFJd]}</CCell></TableRow>
                                    <TableRow><CCell colSpan={2}>复检人员</CCell><CCell colSpan={2}></CCell></TableRow>
                                </TableBody>
                            </Table>
                        </div>
                        :
                        printing?  null :
                            <DirectLink  href={urlhead+`/${utag}#${utag}`}>
                                <Button variant="ghost" intent='primary' block css={{"@media print": {display: 'none'} }}  noBind >
                                    {label}
                                </Button>
                            </DirectLink>
                }
            </React.Fragment>;
        }) }
    </>;
};
